local FightBehavior = require("gameLogic.fight.fightBehavior.FightBehavior")
local ConfusionBahavior = class("ConfusionBahavior", FightBehavior)

function ConfusionBahavior:ctor()
    ConfusionBahavior.super.ctor(self)
end

function ConfusionBahavior:excute(battleReport)
    local skill = self._entity:getNormalSKill()
    local entitys = self:getSkillTargetEntity(skill)
    battleReport:addAttackSkillId(skill:getId())
    skill:actOn(entitys, battleReport)
    self._entity:dispatchActionEnd()
end

function ConfusionBahavior:getSkillTargetEntity(skill)
    local FightConst = require("const.FightConst")
    local FightHelper = require("gameLogic.fight.FightHelper")
    local target = skill:getTarget()
    local enemys = self:getTargetEntitys()
    if target == FightConst.SKILL_TARGET_RANDOM then
        return FightHelper.shuffleGetList(enemys, skill:getAmount())
    elseif target == FightConst.SKILL_TARGET_SINGLE then
        return FightHelper.shuffleGetList(enemys, 1)
    elseif target == FightConst.SKILL_TARGET_ALL then
        return enemys
    elseif target == FightConst.SKILL_TARGET_COLUMN then
        return FightHelper.shuffleGetColList(enemys)
    elseif target == FightConst.SKILL_TARGET_ROW then
        return FightHelper.shuffleGetRowList(enemys)
    end
    return {}
end

function ConfusionBahavior:getTargetEntitys()
    local FightConst = require("const.FightConst")
    local friends = self._entity:getFriends()
    local myId = self._entity:getId()
    local result = {}
    for i = 1, #friends do
        if friends[i]:getId() ~= myId then
            table.insert(result, friends[i])
        end
    end
    return result
end

return ConfusionBahavior
